package com.etime.shycourse.services.ad.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shycourse.dao.AdLogMapper;
import com.etime.shycourse.dto.CourseOfflineDto;
import com.etime.shycourse.pojo.AdLog;
import com.etime.shycourse.pojo.Course;
import com.etime.shycourse.services.ad.interfaces.AdWxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author why
 * @data 2022/7/19 15:27
 */
@Service
public class AdWxServiceImpl implements AdWxService {
    @Autowired
    private AdLogMapper adLogMapper;

    /**
     * 根据广告位置类型查询在当前日期内的广告
     * @param placeid
     * @return
     */
    @Override
    public List<AdLog> selectAdLogByAdPlace(Long placeid) {
        Date date = new Date();
        QueryWrapper<AdLog> wrapper = new QueryWrapper<>();
        wrapper.eq(placeid!=null,"placeid",placeid);
        wrapper.eq("adstate",1);
        wrapper.orderByAsc("adsort");
        wrapper.gt("adstart",date);
        wrapper.lt("adend",date);
        return adLogMapper.selectList(wrapper);
    }

    /**
     * 根据广告位置类型查询在当前日期内的广告课程
     *
     * @param placetype
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public Page<CourseOfflineDto> selectCourseByPlaceType(Long placetype, Long pageNum, Long pageSize) {
        Page<CourseOfflineDto> page = new Page<>(pageNum,pageSize);
        Date nowTime = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String date = sdf.format(nowTime);
        return adLogMapper.selectCourseByPlaceType(page,placetype,date);
    }


}
